import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex) // vue的插件机制

// Vuex.Store 构造器选项
const store = new Vuex.Store({
  state: {
    // 用户信息
    userInfo: {},
    // 用户角色
    userRole:uni.getStorageSync('userRole') || '',
	//jdgcrecid
	 jdgcrecid:uni.getStorageSync('jdgcrecid') || '',
    // 登录token
    token: uni.getStorageSync('token') || '',
    // 用户所在机构id
    companyId: uni.getStorageSync('companyId') || '',
    // token过期标识
    tokenInvalidFlag: false,
    // popup打开状态（用于全局处理层级叠盖问题）
    popupOpen:false
  },
  mutations: {
    setPopupOpen(state, popupOpen) {
      state.popupOpen = popupOpen
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo
    },
    setUserCompanyId(state,companyId){
      state.companyId = companyId
      uni.setStorageSync('companyId', companyId)
    },
    setUserRole(state, userRole) {
      state.userRole = userRole
      uni.setStorageSync('userRole', userRole)
    },
	setUserRole(state, jdgcrecid) {
	  state.jdgcrecid = jdgcrecid
	  uni.setStorageSync('jdgcrecid', jdgcrecid)
	},
    setToken(state, token) {
      state.token = token
      uni.setStorageSync('token', token)
    },
    logout(state) {
      state.token = ''
      state.userRole = ''
	  state.jdgcrecid= ''
      state.userInfo = {}
      uni.removeStorageSync('token')
    },
    commonSet(state, {
      key,
      value
    }) {
      if (Object.prototype.hasOwnProperty.call(state, key)) {
        state[key] = value;
      }
    }
  },
  actions: {}
})

export default store
